package cn.edu.ylu.gaoxin.controller;

import java.util.ArrayList;

import com.jfinal.core.Controller;

import cn.edu.ylu.gaoxin.model.GoodsDesc;
import cn.edu.ylu.gaoxin.model.Shop;

/**
 * 前端店铺控制器
 *    abc.com/shop/123
 */
public class ShopController extends Controller {
	
		public void index(){
			String shop_id;
			Shop shop = null;
			ArrayList<GoodsDesc> goodsList = null;
			try{
				//获取店铺id
				shop_id = getPara(0);
				//查询店铺信息
				//select * from shop where shop_id = shop_id;
				shop = Shop.dao.getOne(shop_id);
				//查询店铺的商品
				goodsList =  (ArrayList<GoodsDesc>) Shop.dao.getAllGoods(shop_id);
				//返回数据
				//renderText("ID:"+shop.getShopId()+"NAME: "+shop.getShopName());
				setAttr("shop",shop);
				setAttr("goodsList",goodsList);				
				render("/shop.html");
				return;
			}catch(Exception e){
				this.redirect("/shops");
				return;
			}
			
		}
		
}
